﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.EntityClient;
using System.Data.Linq;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using QuaManSys;
namespace QuaManSys.InnerInfo
{
    public partial class InnerInfoDistribute : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) 
            { 
                //GetProjectNumbers();
                lblInnerNo.Text = Request.QueryString["id"];
                ShowInfo(lblInnerNo.Text);
            }
         

        }
/// <summary>
/// 显示数据库中所有编号
/// </summary>
        //private void GetProjectNumbers()
        //{
        //    using (var context = new QuaManSysEntities())
        //    {
        //        try
        //        {

        //            ListItem initLi = new ListItem("--请选择--");
        //            InfoIdlist.Items.Insert(0, initLi);
        //            int count = 1;
        //            foreach (var item in context.InnerQualityInfo)
        //            {
        //                ListItem li = new ListItem(item.qualityInfoId);
        //                InfoIdlist.Items.Insert(count++, li);
        //            }
        //        }
        //        catch (EntitySqlException ex)
        //        {
        //            Console.WriteLine(ex.ToString());
        //        }

        //    }
        //}

        /// <summary>
        ///通过qualityInfoId显示信息
        /// </summary>
        /// <param name="qualityInfoId"></param>
        protected void ShowInfo(string qualityInfoId)
        {  using(var db=new QuaManSysEntities())
           {
                var query = db.InnerQualityInfo.Find(qualityInfoId);
                //lblNo.Text=query.qualityInfoId;
                ddlProNo.Text=query.projectNo;
                txtComponent.Text=query.components;
                txtManufac.Text=query.producer ;
                txtFaiTyp.Text=query.faultType;
                if(query.projectCategory=="已处理")
                     CheckBox1.Checked=true;
                else  CheckBox2.Checked=true;
                txtPjNam.Text=query.name;
                txtProDL.Text=Convert.ToString(query.deadline);
                txtCustomer.Text=query.customerLinker;
                txtCusTel.Text=query.telephone;
                txtSpeReq.Text=query.specialDemands;
                DDLInfoCla.Text=query.informationSource;
                DDLImpLev.Text=query.levelOfImportance;
                txtInfoDsc.Text=query.description;
                txtInfoWrt.Text=query.registrantName;
                txtInfoDep.Text=query.registrantDepart;
                //registDate = Convert.ToDateTime(txtWrtDat.Text),
                txtWrtDat.Text=Convert.ToString(query.registDate);
                txtReqAdv.Text=query.recommendedTreatPlan;
                lblState.Text = query.processingStatus;
                txtReqRsl.Text=query.processingResults;
                txtProCmm.Text=query.processingAssess;
                txtPjCls.Text =query.informationCategory;

           }
        
        
        }




        /// <summary>
        /// 质保部门修改后分发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnInfoSub_Click(object sender, EventArgs e)
        {
            string infoCat = "";
            if (CheckBox1.Checked) infoCat = "已处理（需后继关注）";
            if (CheckBox2.Checked) infoCat = "未处理（需跟踪处理）";



            InnerQualityInfo insertInner = new InnerQualityInfo
            {
                qualityInfoId = lblInnerNo.Text,
                projectNo = ddlProNo.Text,
                components = txtComponent.Text,
                producer = txtManufac.Text,
                faultType = txtFaiTyp.Text,
                projectCategory = infoCat,
                name = txtPjNam.Text,
                deadline = Convert.ToDateTime(txtProDL.Text),
                customerLinker = txtCustomer.Text,
                telephone = txtCusTel.Text,
                specialDemands = txtSpeReq.Text,
                informationSource = DDLInfoCla.Text,
                levelOfImportance = DDLImpLev.Text,
                description = txtInfoDsc.Text,
                registrantName = txtInfoWrt.Text,
                registrantDepart = txtInfoDep.Text,
                //registDate = Convert.ToDateTime(txtWrtDat.Text),
                registDate = DateTime.Now.Date,
                recommendedTreatPlan = txtReqAdv.Text,
                processingStatus = "分发",
                processingResults = txtReqRsl.Text,
                processingAssess = txtProCmm.Text,
                informationCategory = txtPjCls.Text
            };
            InnerResponsibleDepart resDept = new InnerResponsibleDepart
            {
                department = DDLDepRes.Text,
                qualityInfoId = lblInnerNo.Text,
                isResponDepart = 1
            };

            //InnerResponsibleDepart dept = new InnerResponsibleDepart
            //{
            //    department = DDLDepFoc.Text,
            //    qualityInfoId = lblNo.Text,
            //    isResponDepart = 0
            //};

            using (var db = new QuaManSysEntities())
            {
                db.InnerQualityInfo.Add(insertInner);
                db.SaveChanges();
                db.InnerResponsibleDepart.Add(resDept);
                db.SaveChanges();
                //db.InnerResponsibleDepart.Add(dept);
                //db.SaveChanges();


            }
        }

        //protected void InfoIdlist_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    ShowInfo(lblInnerNo.Text);
        //}
    }
}